use strict;
use warnings;

my ($datafile, $gene) = @ARGV;
open (my $datafileh, $datafile) or die('No datafile.');

my $realtag = '1.CEL';
my $faketag = '4.CEL';

my @reals;
my @fakes;

my @file = <$datafileh>;
my @header = split /,\s*/, $file[0];
my $headerlength = @header;

for (my $i = 0; $i < $headerlength; $i++){
    if($header[$i] =~ /$realtag/){
        push(@reals, $i);
    }
    if($header[$i] =~ /$faketag/){
        push(@fakes, $i);
    }
}

my $output;

while (my $line = <$datafileh>){
    chomp $line;
    my @data = split /,\s*/, $line;
    if($data[0] =~ /$gene/){
        foreach my $realnum (@reals){
            $output = $output . @data[$realnum] . ",";
        }
        foreach my $fakenum (@fakes){
            $output = $output . @data[$fakenum] . ",";
        }
    }
    last;
}

print $output;